import { createRouter, createWebHistory } from "vue-router";
import Layout from "../components/Layout.vue";

const routes = [
  // 根路径重定向
  {
    path: "/",
    redirect: "/financial/tax", // 默认跳转到预算与成本管理
  },

  // 财务模块路由
  {
    path: "/financial",
    component: Layout,
    children: [
      {
        path: "tax",
        name: "税务管理",
        component: () => import("../views/financial/tax/Index.vue"),
        meta: { title: "税务管理" },
      },
      {
        path: "reports",
        name: "财务报表管理",
        component: () => import("../views/financial/reports/Index.vue"),
        meta: { title: "财务报表管理" },
      },
      {
        path: "rent-fees",
        name: "租金与费用管理",
        component: () => import("../views/financial/rent-fees/Index.vue"),
        meta: { title: "租金与费用管理" },
      },
      {
        path: "budget-cost",
        name: "预算与成本管理",
        component: () => import("../views/financial/budget-cost/Index.vue"),
        meta: { title: "预算与成本管理" },
      },
      {
        path: "exceptions",
        name: "异常处理与数据安全",
        component: () => import("../views/financial/exceptions/Index.vue"),
        meta: { title: "异常处理与数据安全" },
      },
      {
        path: "tax/taxPage",
        name: "税务申报详情",
        component: () => import("../components/financial/TaxForm.vue"),
        meta: { title: "税务申报详情" },
      },
      {
        path: "rent-fees/billPage:billNumber",
        name: "账单详情",
        component: () => import("../components/financial/BillForm.vue"),
        meta: { title: "账单详情" },
      },
    ],
  },

  // 404页面捕获（必须放在最后）
  {
    path: "/:pathMatch(.*)*",
    name: "NotFound",
    component: () => import("../views/Error404.vue"),
    meta: { title: "页面不存在" },
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

// 设置页面标题
router.beforeEach((to) => {
  if (to.meta.title) {
    document.title = `${to.meta.title} - 智慧园区系统`;
  }
});

export default router;
